﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IUserRecommendationService
    {
        IQueryable<UserRecommendation> GetUserRecommendations();
        UserRecommendation GetUserRecommendation(int id);
        void CreateUserRecommendation(UserRecommendation userRecommendation);
        void DeleteUserRecommendation(int id);
        void SaveUserRecommendation();
    }
    
    public class UserRecommendationService : IUserRecommendationService
    {
        private readonly IUserRecommendationRepository userRecommendationRepository;
        private readonly IUnitOfWork unitOfWork;
        public UserRecommendationService(IUserRecommendationRepository userRecommendationRepository, IUnitOfWork unitOfWork)
        {
            this.userRecommendationRepository = userRecommendationRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IUserRecommendationService Members

        public IQueryable<UserRecommendation> GetUserRecommendations()
        {
            var userRecommendations = userRecommendationRepository.GetAll();
            return userRecommendations;
        }

        public UserRecommendation GetUserRecommendation(int id)
        {
            var userRecommendation = userRecommendationRepository.GetById(id);
            return userRecommendation;
        }

        public void CreateUserRecommendation(UserRecommendation userRecommendation)
        {
            userRecommendationRepository.Add(userRecommendation);
            SaveUserRecommendation();
        }

        public void DeleteUserRecommendation(int id)
        {
            var userRecommendation = userRecommendationRepository.GetById(id);
            userRecommendationRepository.Delete(userRecommendation);
            SaveUserRecommendation();
        }

        public void SaveUserRecommendation()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}